package com.example.springboot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by yxw on 2017/8/23.
 */

@RestController
@Controller
public class HelloController {


    @Autowired
    private DiscoveryClient discoveryClient;


    @RequestMapping("hello")
    public String index() {
        ServiceInstance instance = discoveryClient.getLocalServiceInstance();
        System.out.println("/hello,host" + instance.getHost() + ", server_id:" + instance.getServiceId());
        return "hello";
    }

    @RequestMapping(value = "hello2")
    public String hello(@RequestParam String name) {
        return "hello" + name;
    }

    /*@RequestMapping(value = "hello3")
    public User hello(String name, Integer age) {
        return new User(name, age);
    }

    @PostMapping(value = "hello4")
    public String hello(@RequestBody User user) {
        return "Hello" + user.getName() + ", " + user.getAge();
    }*/
}
